/***************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName   : TableCommon.cpp
  *Author     : scofined.qi
  *Version    : 1.0
  *Date       : 2016/06/12
  *Desc       : //用于说明此程序文件完成的主要功能
  *Relation   :
  *Other      : //其他内容说明
  *Function   : //主要函数列表，每条记录应包含函数名及功能简要说明
  *History    : //修改历史纪录列表，每条修改记录应包含修改日期，修改者以及修改内容简介
  ***************************************************************************************/

#include "TableCommon.h"
#include <time.h>
#include <core/strings/Rand.h>
#include <core/Utility.h>

using namespace qb::base;
namespace qb{
	namespace ht{

		BondKeyGenerator::BondKeyGenerator()
		{
			for (char c = 'A'; c <= 'Z'; c++)
			{
                std::string str; str.push_back(c);
				m_part1.push_back(str);
			}
			m_part1.push_back("DSC");
			m_part1.push_back("SH");

			m_part3.push_back("ABSAMP");
			m_part3.push_back("ABSCBS");
			m_part3.push_back("ABSLBS");
			m_part3.push_back("ABSMBS");
			m_part3.push_back("CBB");
			m_part3.push_back("CBBSCB");
			m_part3.push_back("CORCCB");
			m_part3.push_back("CORCCP");
			m_part3.push_back("CORCEB");
			m_part3.push_back("CORCMN");
			m_part3.push_back("CORCOB");
			m_part3.push_back("CORCSP");
			m_part3.push_back("CORCVB");
			m_part3.push_back("CORLCP");
			m_part3.push_back("CORLEB");
			m_part3.push_back("CORLMN");
			m_part3.push_back("CORLSP");
			m_part3.push_back("CORPPN");
			m_part3.push_back("CORRAB");
			m_part3.push_back("CORSCB");
			m_part3.push_back("CORSCV");
			m_part3.push_back("FINCBB");
			m_part3.push_back("FINCSB");
			m_part3.push_back("FINCXB");
			m_part3.push_back("FINNCB");
			m_part3.push_back("FINPBB");
			m_part3.push_back("FINPSB");
			m_part3.push_back("FINSEB");
			m_part3.push_back("FINSES");
			m_part3.push_back("FINSSB");
			m_part3.push_back("GBBHJB");
			m_part3.push_back("GBBRAB");
			m_part3.push_back("GOVBGB");
			m_part3.push_back("INT");
			m_part3.push_back("LGBLLB");
			m_part3.push_back("LGBTLB");
			m_part3.push_back("NCD");
		}

		BondKeyGenerator& BondKeyGenerator::Get()
		{
			static BondKeyGenerator bkg;
			return bkg;
		}

		int BondKeyGenerator::Make(char* buf, int size)
		{
			char* ptr = buf; char* pend = buf + size - 1;
			int ncount = 0;
            std::string& str1 = m_part1.at(Rand::RandInt(0, m_part1.size()));
            std::string& str3 = m_part3.at(Rand::RandInt(0, m_part3.size()));
			memcpy(ptr, str1.c_str(), str1.size()); ptr += str1.size();
			ncount = FMTBUFN(ptr, pend - ptr,"%06d", Rand::RandInt(1, 999999)); ptr += ncount;
			ncount = FMTBUFN(ptr, pend - ptr, "%04d", Rand::RandInt(2000, 2017)); ptr += ncount;
			memcpy(ptr, str3.c_str(), str3.size()); ptr += str3.size();
			ncount = FMTBUFN(ptr, pend - ptr, "%0d", Rand::RandInt(1, 9999));
			ptr += ncount;
			return ptr - buf;
		}
	}//namespace ht
}//namespace qb
